package com.app.backend.activiti.controller;

import cn.hutool.core.util.StrUtil;
import com.app.backend.common.response.BaseResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.HistoryService;
import org.activiti.engine.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: ActTaskController
 * @description:
 * @author: Zhun.Xiao
 * @create: 2020-02-27 10:46
 **/


@Slf4j
@RestController
@Api("任务管理")
@RequestMapping("/api/v1/act/task")
public class ActTaskController {
    @Autowired
    private TaskService taskService;

    @Autowired
    private HistoryService historyService;
    //todo 我的代办列表


    //todo 我的已办列表


    //todo 流程流转历史

    //todo 当前任务节点审批通过

    //todo 批量通过

    //todo back - 驳回至发起人

    //todo backBatch  - 批量驳回

    @PostMapping("/delete")
    @ApiOperation("删除任务")
    public BaseResponse deleteTask(@ApiParam("任务id") @RequestParam String[] ids,
                                   @ApiParam("原因") @RequestParam String reason) {
        if (StrUtil.isBlank(reason)) {
            reason = "";
        }
        for (String id : ids) {
            taskService.deleteTask(id,reason);
        }
        return new BaseResponse();
    }


    @PostMapping("/deleteHist")
    @ApiOperation("删除任务")
    public BaseResponse deleteHistTask(@ApiParam("任务id") @RequestParam String[] ids) {
        for (String id : ids) {
            historyService.deleteHistoricTaskInstance(id);
        }
        return new BaseResponse();
    }

}